博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[AngularJS] Isolate State Mutations in Angular Components
阅读量:5878 次
发布时间:2019-06-19

本文共 1247 字,大约阅读时间需要 4 分钟。

Managing state is one of the hardest things to do in any application. Angular 2 tackles this problem by making it easy to implement a reactive, uni-directional data flow that favor immutable operations. We are moving in the right direction in Angular 1 by moving our state and logic to models but invariably this raises a question. If we are moving to an immutable world, how do you manage mutable operations like forms in Angular? In this lesson, we are going to learn a surprisingly simple technique to isolate state mutations within a component using component lifecycle hooks.

 

For example you have a bookmark component, and inside the component, you want to update the bookmark. The solution is you create a component just for update bookmark.

 

And inside the save-bookmark component, you can copy the original data, and modify on the copy data:

class SaveController {  $onChanges() {    this.editedBookmark = Object.assign({}, this.bookmark);  }}export default SaveController;

This can isolate the component state muataion. 

转载地址:http://dgdix.baihongyu.com/

你可能感兴趣的文章
安装错误 ERROR: DW050: - Microsoft Visual C++ 2010 Redistributable Package (x86): Install failed
查看>>
ubuntu 14.04安装quickbuild server (一)
查看>>
jQuery插件开发全解析<转>
查看>>
Swift - 多线程实现方式(2) - NSOperation和NSOperationQueue
查看>>
opencv笔记3:trackbar简单使用
查看>>
BZOJ4294 : [PA2015]Fibonacci
查看>>
【设计模式】Template Method模式
查看>>
Intel® Ethernet Connection I217-V 网卡驱动(win10 ,2012)
查看>>
android 26 设置项目有多个入口Activity。
查看>>
每天一个linux命令(12):more命令
查看>>
家庭洗车APP --- Androidclient开展 之 网络框架包介绍(一)
查看>>
挖掘算法(1)朴素贝叶斯算法
查看>>
Spring使用Cache、整合Ehcache
查看>>
Index/Common目录下文件
查看>>
Bash 什么时候会给 HOME 赋初始值
查看>>
POJ 3522 Slim Span 最小差值生成树
查看>>
[AlwaysOn Availability Groups]DMV和系统目录视图
查看>>
nginx js、css多个请求合并为一个请求(concat模块)
查看>>
Java系列:《Java核心技术 卷一》学习笔记,chapter11 记录日志
查看>>
python --装饰器
查看>>